package com.um.jdy.platform.device.controller;


import com.um.jdy.common.device.entity.dto.GunDTO;
import com.um.jdy.common.device.entity.po.Gun;
import com.um.jdy.platform.device.entity.dto.GunPageDTO;
import com.um.jdy.platform.device.entity.dto.GunPageParams;
import com.um.jdy.platform.device.entity.dto.PortRestartDTO;
import com.um.jdy.platform.device.entity.vo.PageGunVO;
import com.um.jdy.platform.device.manger.GunManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 控制器：充电枪表
 */
@RestController
@RequestMapping("/api/v1/cms/device/gun")
@Api(tags = "设备管理", description = "充电枪表")
@ApiPermission("gun")
@TokenRequired
@Validated
public class GunController extends BaseController<GunManager> {

    /**
     * 分页查询充电枪
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("分页查询")
    @PostMapping("/page")
    public Response<Page<Gun>> getPage(@RequestBody GunPageParams params){
        PageParams pageParams = params.toPageParams(new String[]{"devicePileId"},new String[]{"device_pile_id"});
        return manager.getPage(pageParams);
    }

    /**
     * 分页查询充电枪
     * @param params
     * @return
     */
    @ApiPermission("gun_page")
    @ApiOperation("分页查询")
    @PostMapping("/get_page")
    public Response<Page<PageGunVO>> getGunPage(@RequestBody GunPageDTO params){
        PageParams pageParams = params.toPageParams(
                new String[]{"status","platformMerchantId","deviceStationId","code","name"},
                new String[]{"g.status","d.platform_merchant_id","d.device_station_id","d.code","d.name"});
        return manager.getGunPage(pageParams);
    }

    @ApiPermission("update")
    @ApiOperation("更新")
    @PutMapping({"{id}"})
    public Response<Gun> update(@PathVariable String id, @RequestBody GunDTO dto) {
        return manager.updateEntity(id, dto);
    }

    @ApiPermission("restart")
    @ApiOperation("端口重启")
    @PostMapping({"restart"})
    public Response restart(@RequestBody PortRestartDTO dto) {
        return manager.restart(dto);
    }

}
